<?php

class Search extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->service('Service_search');
        $this->load->library('FileUtil');
    }

    public function index($key = '', $page = 1)
    {
        $key = empty($key) ? $this->getParams()['key'] : $key;
        $key = htmlspecialchars(urldecode($key));
        if (!empty($key)) {
            $ip = $_SERVER['REMOTE_ADDR'];
            $this->Service_search->add($key, $ip);
        }

        $list = $this->Service_search->getList($key, $page);
        $this->assign('key', $key);
        $this->assign('search', true);
        $this->assign('urls', $list);
        $this->display("index.tpl");
    }

    public function hot()
    {
        $list = $this->Service_search->getHot();
        $this->assign('key', '热搜');
        $this->assign('list', $list);
        $this->display("hot/index.tpl");
    }
}
